package com.order.interceptor.sys;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;
import com.order.shiro.ShiroUtils;


/** 
* @ClassName: LoginInterceptor 
* @Description: 全局拦截器
* @author LinBo
* @date 2014年3月22日 下午4:58:50 
*  
*/ 
public class LoginInterceptor implements Interceptor{
	
	private static final Logger logger = LoggerFactory.getLogger(LoginInterceptor.class);

	@Override
	public void intercept(ActionInvocation ai) {
		Controller controller = ai.getController();
		String contentPath = controller.getRequest().getContextPath();
		controller.setAttr("root", contentPath);
		controller.setAttr("serverName", controller.getRequest().getServerName());
		logger.info("全局拦截器,拦截上下文地址" + contentPath);
		System.out.println("权限拦截器拦截用户:"+ShiroUtils.getUser());
		String uri = controller.getRequest().getRequestURI();
		if(uri.contains("/sys")){
			if(ShiroUtils.getUser() == null){
				logger.info("用户未登录，重定向登录页面");
				controller.redirect("/common");
			}else{
				ai.invoke();
			}
		}else{
			ai.invoke();
		}
		logger.info("全局拦截后");
	}
}
